***create treatment vars
gen treat= info_suc
replace treat=2 if pledge_suc==1
tab treat if wra==1

gen assign= info_ass
replace assign=2 if pledge_ass==1
tab assign if wra==1

tab info_ass info_suc, row
tab pledge_ass pledge_suc, row
tab treat_ass treat_suc,row


***average ITT for students in treated sections****
reg voted treat_suc if wra==1, robust cluster(uniquesection)
reg voted treat_suc afam asian latino female age  crsa crsb if wra==1, robust cluster(uniquesection)
reg voted info_suc pledge_suc if wra==1, robust cluster(uniquesection)
reg voted info_suc pledge_suc afam asian latino  female age  crsa crsb if wra==1, robust cluster(uniquesection)

reg voted treat_suc if wra==1 & regpresept9==1, robust cluster(uniquesection)
reg voted treat_suc afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted info_suc pledge_suc if wra==1  & regpresept9==1, robust cluster(uniquesection)
test info_suc=pledge_suc
reg voted info_suc pledge_suc afam asian latino age  female crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
test info_suc=pledge_suc

reg voted treat_suc if wra==1 & regpresept9==0, robust cluster(uniquesection)
reg voted treat_suc afam asian latino female age  crsa crsb if wra==1  & regpresept9==0, robust cluster(uniquesection)
reg voted info_suc pledge_suc if wra==1  & regpresept9==0, robust cluster(uniquesection)
test info_suc=pledge_suc
reg voted info_suc pledge_suc afam asian latino age  female crsa crsb if wra==1  & regpresept9==0, robust cluster(uniquesection)
test info_suc=pledge_suc

reg regpostsept9 treat_suc if wra==1 & regpresept9==0, robust cluster(uniquesection)
reg regpostsept9 treat_suc afam asian latino  female age  crsa crsb if wra==1 & regpresept9==0, robust cluster(uniquesection)
reg regpostsept9 info_suc pledge_suc if wra==1 & regpresept9==0, robust cluster(uniquesection)
reg regpostsept9 info_suc pledge_suc afam asian latino  female age  crsa crsb if wra==1 & regpresept9==0, robust cluster(uniquesection)

**average ITT for female,afam,latino,asian
reg voted treat_suc##female afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted treat_suc##afam afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted treat_suc##asian afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted treat_suc##latino afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)

reg voted info_suc##female pledge_suc##female afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted info_suc##afam pledge_suc##afam afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted info_suc##asian pledge_suc##asian afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)
reg voted info_suc##latino pledge_suc##latino afam asian latino female age  crsa crsb if wra==1  & regpresept9==1, robust cluster(uniquesection)

**create variables for roommate analysis

*count nonmissing number of roommates assigned to treatment or control, excluding observation i; we will exclude those for whom count=0
egen countwra=count(treat_suc) if uniquerm!=., by(uniquerm)
gen selfwra=(treat_suc==0 | treat_suc==1)
replace countwra=countwra-selfwra

*create control variable for being assigned to WRA treatment; 0=control, 1=info, 2=pledge, 3=not in experiment
gen newtreat=treat
replace newtreat=3 if newtreat==.

*for each treatment variable, create indicator if a roommate other than i received treatment
gen treat2_suc=treat_suc
replace treat2_suc=0 if treat_suc==.
egen totaltreat = total(treat2_suc) if uniquerm!=., by(uniquerm)
replace totaltreat=totaltreat-treat2_suc
replace totaltreat=1 if totaltreat>1 & totaltreat!=.

gen info2_suc=info_suc
replace info2_suc=0 if info_suc==.
egen totalinfo = total(info2_suc) if uniquerm!=., by(uniquerm)
replace totalinfo=totalinfo-info2_suc
replace totalinfo=1 if totalinfo>1 & totalinfo!=.

gen pledge2_suc=pledge_suc
replace pledge2_suc=0 if pledge_suc==.
egen totalpledge = total(pledge_suc) if uniquerm!=., by(uniquerm)
replace totalpledge=totalpledge-pledge2_suc
replace totalpledge=1 if totalpledge>1 & totalpledge!=.

***roommate analysis
reg voted totaltreat i.newtreat if countwra!=0 &  N_rmmates!=1 , robust cluster(uniquerm)
reg voted totaltreat i.newtreat afam asian latino female  age  i.N_r if countwra!=0 &  N_rmmates!=1 , robust cluster(uniquerm)
reg voted totalinfo totalpledge i.newtreat if countwra!=0 &  N_rmmates!=1 , robust cluster(uniquerm)
reg voted totalinfo totalpledge i.newtreat afam asian latino female age  i.N_r if countwra!=0 &  N_rmmates!=1 , robust cluster(uniquerm)

reg voted totaltreat i.newtreat if countwra!=0 &  N_rmmates!=1 & regpresept9==1, robust cluster(uniquerm)
reg voted totaltreat i.newtreat afam asian latino female  age  i.N_r if countwra!=0 &  N_rmmates!=1 & regpresept9==1, robust cluster(uniquerm)
reg voted totalinfo totalpledge i.newtreat if countwra!=0 &  N_rmmates!=1 & regpresept9==1, robust cluster(uniquerm)
test totalinfo=totalpledge
reg voted totalinfo totalpledge i.newtreat afam asian latino female age  i.N_r if countwra!=0 &  N_rmmates!=1 & regpresept9==1, robust cluster(uniquerm)
test totalinfo=totalpledge

reg voted totaltreat i.newtreat if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
reg voted totaltreat i.newtreat afam asian latino female  age  i.N_r if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
reg voted totalinfo totalpledge i.newtreat if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
test totalinfo=totalpledge
reg voted totalinfo totalpledge i.newtreat afam asian latino female age  i.N_r if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
test totalinfo=totalpledge

reg regpost totaltreat i.newtreat if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
reg regpost totaltreat i.newtreat afam asian latino female  age  i.N_r if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
reg regpost totalinfo totalpledge i.newtreat if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)
reg regpost totalinfo totalpledge i.newtreat afam asian latino female age  i.N_r if countwra!=0 &  N_rmmates!=1 & regpresept9==0, robust cluster(uniquerm)

***roommate analysis: female 
gen male=1-female
egen allfemale = min(female) if uniquerm!=., by(uniquerm) 
egen allmale = min(male) if uniquerm!=., by(uniquerm) 

reg voted totaltreat##allfemale i.newtreat if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1), robust cluster(uniquerm)
reg voted totaltreat##allfemale i.newtreat afam asian latino age  i.N_r if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1), robust cluster(uniquerm)
reg voted totalinfo##allfemale totalpledge##allfemale i.newtreat if countwra!=0 &  N_rmmates!=1& (allfemale==1 | allmale==1), robust cluster(uniquerm)
reg voted totalinfo##allfemale totalpledge##allfemale i.newtreat afam asian latino age  i.N_r if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1), robust cluster(uniquerm)

reg voted totaltreat##allfemale i.newtreat if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1) & regpre==1 , robust cluster(uniquerm)
reg voted totaltreat##allfemale i.newtreat afam asian latino age  i.N_r if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1) & regpre==1 , robust cluster(uniquerm)
reg voted totalinfo##allfemale totalpledge##allfemale i.newtreat if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1) & regpresept9==1 , robust cluster(uniquerm)
reg voted totalinfo##allfemale totalpledge##allfemale i.newtreat afam asian latino age  i.N_r if countwra!=0 &  N_rmmates!=1 & (allfemale==1 | allmale==1) & regpresept9==1 , robust cluster(uniquerm)

***randomization check
mlogit treat afam asian latino female age   crsa crsb if wra==1, robust cluster(uniquesec)
mlogit assign afam asian latino female age   crsa crsb if wra==1, robust cluster(uniquesec)
gen rmtreat=totalinfo
replace rmtreat=2 if totalpledge==1
tab rmtreat if countwra!=0 &  N_rmmates!=1
*for purposes of randomization check, if >1 roommates treated, rmtreat=2
mlogit rmtreat afam asian latino female age   i.N_rmmates if N_r!=1 & countwra!=0, robust cluster(uniquerm)
testparm afam asian latino female age 

*descriptives
gen control_suc=1-treat_suc
summ voted treat_suc info_suc pledge_suc control_suc afam asian latino  female age  crsa crsb regpre  if treat_suc!=.
tab1 newtreat, g(newtreat)
summ voted totaltreat totalinfo totalpledge afam asian latino female age  N_r countwra regpre newtreat1 newtreat2 newtreat3 newtreat4 if countwra!=0 &  N_rmmates!=1 & uniquerm!=.

*treatment assignment v. success
tab assign treat, row
tab assign treat if regpre, row

*summarize roommate treatment
replace rmtreat=3 if totalinfo==1 & totalpledge==1
tab rmtreat if countwra!=0 &  N_rmmates!=1
tab rmtreat if countwra!=0 &  N_rmmates!=1 & regpre==1
